package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/7/29 09:24
 * @apiNote
 */

public class Test00682CalPoints {
    public static void main(String[] args) {
        String[] operations = new String[]{"5","2","C","D","+"};
        System.out.println(calPoints(operations));
    }

    public static int calPoints(String[] operations) {
        int[] arr = new int[operations.length];
        int len = 0;
        for (int i = 0; i < operations.length; i++) {
            int temp = 0;
            if (operations[i].equals("+")) {
                temp = arr[len - 1] + arr[len - 2];
            } else if (operations[i].equals("D")) {
                temp = 2 * arr[len - 1];
            } else if (operations[i].equals("C")) {
                len--;
            }else{
                temp = Integer.parseInt(operations[i]);
            }
            arr[len] = temp;
            if (!operations[i].equals("C")){
                len++;
            }
        }
        return Arrays.stream(arr).sum();
    }
}
